package com.five.zhh.fiveinfive.controller;

import com.five.zhh.fiveinfive.common.ZhhResponse;
import com.five.zhh.fiveinfive.room.GameRoom;
import com.five.zhh.fiveinfive.room.GameRoomManager;
import com.five.zhh.fiveinfive.room.entity.vo.GameRoomDetailVo;
import com.five.zhh.fiveinfive.service.GameRoomService;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/gameRoom")
public class GameRoomController {

    @Autowired
    private GameRoomService service;

    @GetMapping("/createRoom")
    public ZhhResponse<String> createRoom() {
        GameRoom gameRoom = GameRoomManager.createGameRoom();
        return ZhhResponse.success(gameRoom.getRoomCode());
    }

    /**
     * 获取房间概况
     */
    @GetMapping("/getRoomOverview")
    public ZhhResponse getRoomOverview() {
        return ZhhResponse.success(service.getRoomOverview());
    }

    @GetMapping("/clearRoom")
    public ZhhResponse clearRoom() {
        return ZhhResponse.success(GameRoomManager.clearGameRoom());
    }

    @GetMapping("/roomDetail/{roomCode}")
    public ZhhResponse<GameRoomDetailVo> roomDetail(@PathVariable("roomCode") String roomCode) {
        return ZhhResponse.success(GameRoomManager.getGameRoomDetail(roomCode));
    }

    @GetMapping("/clearTestRoom")
    public ZhhResponse clearTestRoom() {
        GameRoom gameRoom = GameRoomManager.getGameRoom("1234");
        GameRoomManager.removeGameRoom(gameRoom.getRoomCode());
        return ZhhResponse.success(gameRoom);
    }

    @GetMapping("/createTestRoom")
    public ZhhResponse createTestRoom() {
        GameRoom newRoom = GameRoomManager.createTestGameRoom();
        return ZhhResponse.success();
    }

}
